{extend name="common:base" /}


{block name="breadcrumb"}
<h1>
    单页管理
    <small>单页管理</small>
</h1>
<ol class="breadcrumb">
    <li><a href="{:url('/admin')}"><i class="fa fa-dashboard"></i> 控制台</a></li>
    <li><a href="{:url('/admin/page')}">单页管理</a></li>
    <li class="active">添加单页</li>
</ol>
{/block}


{block name="content"}
<!-- Default box -->

<form action="{:url('/admin/page/add')}" method="post" style="display: block;" id="formDocument">
    <div class="row">
        <!-- left column -->
        <div class="col-md-8">
            <!-- Horizontal Form -->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">基本信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <div class="">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="control-label">标题</label>
                            <div>
                                <input type="text" name="title" class="form-control" id="inputTitle" placeholder="标题">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label">内容</label>
                            <div >
                                <textarea id="editor" name="content"></textarea>
                            </div>
                        </div>


                    </div>
                    <!-- /.box-body -->

                    <!-- /.box-footer -->
                </div>
            </div>
            <!-- /.box -->
        </div>

        <!--/.col (left) -->
        <!-- right column -->
        <div class="col-md-4">
            <!-- general form elements -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">其他信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <div class="box-body">
                    <div class="form-group">
                        <label class="control-label">标识</label>
                        <div>
                            <input type="text" name="mark" class="form-control" id="inputMark">
                        </div>
                    </div>

                    <div class="form-group">
                        <label>启用</label>
                        <div >
                            <label><input type="checkbox" name="status" value="1" class="flat-red" checked> </label>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
            </div>
            <!--&lt;!&ndash; /.box &ndash;&gt;-->
        </div>
        <!--/.col (right) -->
        <div class="col-sm-12 p10">
            <div class="submit-box p10">
                <button type="submit" class="btn btn-danger">提交</button>
                <button type="button" class="btn btn-default btn-cancel">取消</button>
            </div>
        </div>

    </div>
</form>
<!-- /.box -->
{/block}
{block name="js"}
<!-- CK Editor -->
<script src="/static/admin/bower_components/ckeditor/ckeditor.js"></script>
<script>
    CKEDITOR.replace('editor',{
        // uiColor: '#00c0ef',
        height: 200,
        // 图片上传相关
        filebrowserImageUploadUrl : './upload',// 图片上传路径
        image_previewText : ' ', // 图片信息面板预览区内容的文字内容，默认显示CKEditor自带的内容
        removeDialogTabs : 'image:advanced;image:Link', // 移除图片上传页面的'高级','链接'页签
    });
    // init validate
    $.validator.setDefaults({
        submitHandler: function(form) {
            // form.submit();
            var url = $(form).attr('action');
            var content = CKEDITOR.instances.editor.getData();
            var data = $(form).serialize();
            data += '&content='+content;
            $.ajax({
                url: url,
                type : "POST",
                data: data,
                success: function(result){
                    if (result.code === 1){
                        $.notify({
                            message: result.msg,
                            icon: 'glyphicon glyphicon-ok'
                        }, {
                            allow_dismiss: true,
                            type: 'success'
                        });
                        var tOut = setTimeout(function(){
                            clearTimeout(tOut);
                            window.location.href = result.url;
                        },1000);
                    }else{
                        $.notify({
                            message: result.msg,
                            icon: 'glyphicon glyphicon-warning-sign'
                        }, {
                            allow_dismiss: true,
                            type: 'warning'
                        });
                    }
                }

            });
        },
        errorPlacement: function(error, element) {
            $(element).parent().append(error);
        }
    });
    $("#formDocument").validate({
        rules: {
            title: 'required',
            content: 'required',
        },
        messages: {
            title: "请输入标题",
            content: "请输入内容",
        }
    });



</script>
{/block}